import axios from "axios"
import { message } from "antd"
export const request = axios.create({
  timeout: 10000,
})
request.interceptors.request.use((config) => {
  console.log("数据发送前····可以做点事情")
  config.headers.token=localStorage.getItem("token")
  return config
},error=>{
  return Promise.reject(error)
})
request.interceptors.response.use(response=>{
  const {code,data,message:respMessage}=response.data;
  if(code===400){
    message.error(respMessage)
  }
  return response.data
},error=>{
  const {status}=error.response;
  if(status>=400&&status<500){
    message.error("客户端请求错误!!!!")
  }
  if(status>=500){
    message.error("服务器内部错误!!!!")
  }
  return Promise.reject(error)
})